import greenfoot.*;

/**
 * This class defines a crab. Crabs live on the beach.
 */
public class Crab extends Actor
{
    private int mark = 1,a=0;
    public void act()
    {
        move(10);
        turnAtEdge();
        control();
        animation();
        if(isTouching(Worm.class)){
            removeTouching(Worm.class);
            Greenfoot.playSound("slurp.wav");
            a++;
            CrabWorld w=(CrabWorld)getWorld();
            w.showScore(a);
        }
        if(a==5){
            Greenfoot.playSound("fanfare.wav");
            Greenfoot.stop();
        }
    }
    public void turnAtEdge(){
        if(isAtEdge())
            turn(30);
    }
    public void control(){
    if(Greenfoot.isKeyDown("left"))
        turn(-10);
    if(Greenfoot.isKeyDown("right"))
        turn(10);
    }
    public void animation(){
        if(mark == 1){
            setImage("crab2.png");
            mark = 2;
        } else{
            setImage("crab.png");
            mark = 1;
        }
    }
}


